package com.design.movieticket.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.design.movieticket.common.base.constant.Result;
import com.design.movieticket.common.base.constant.ResultStatus;
import com.design.movieticket.common.dto.XPage;
import com.design.movieticket.entity.Cinema;
import com.design.movieticket.service.CinemaService;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@Slf4j
@Api(tags = "影院模块")
@RestController
@RequestMapping("/cinema")
public class CinemaController{
    @Resource
    private CinemaService cinemaService;

    /** 分页查询 */
    @ApiOperation("影院信息分页展示")
    @GetMapping("/list/page")
    public Result findCinemaListByPage(Cinema cinema, String username, String userRole,XPage<Void> page) {
        IPage<Cinema> CinemaList = cinemaService.page(XPage.toIPage(page), cinemaService.buildQuery(cinema,username,userRole));
        return new Result(CinemaList, ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }

    /** 新增或更新影院数据 */
    @ApiOperation("新增或更新影院数据")
    @PostMapping("/addOrUpdate")
    public Result addOrEditCinema(@RequestBody Cinema cinema) {
        cinemaService.addOrUpdateCinemaInfo(cinema);
        return new Result(ResultStatus.SAVE_SUCCESS.getMsg(),ResultStatus.SAVE_SUCCESS.getCode());
    }

    /** 根据登录用户获取影院id */
    @ApiOperation("获取影院信息详情")
    @GetMapping("/getCinemaId/{loginUser}")
    public Result getCinemaDetail(@PathVariable String loginUser){
        return new Result(cinemaService.getCinemaId(loginUser),ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }

    /** 获取影院信息 */
    @ApiOperation("获取影院信息详情")
    @GetMapping("/getCinemaDetail/{id}")
    public Result getCinemaDetail(@PathVariable long id){
        return new Result(cinemaService.getCinemaDetail(id),ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }

    /** 删除影院信息 */
    @ApiOperation("删除影院信息")
    @PostMapping("/delCinemaById/{id}")
    public Result delCinemaById(@PathVariable long id){
        cinemaService.delCinemaById(id);
        return new Result(ResultStatus.DELETE_SUCCESS.getMsg(),ResultStatus.DELETE_SUCCESS.getCode());
    }

    /** 获取管理员列表 */
    @GetMapping("/getAdmin")
    public Result getAdmin(){
        return new Result(cinemaService.getAdmin(),ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }




    /** 前端获取影院列表  */
    @GetMapping("/wxGetCinemaList")
    public Result wxGetCinemaList(String movieName, String selectDay){
        return new Result(cinemaService.wxGetCinemaList(movieName,selectDay),ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }
}
